/**
 * 
 */
package com.vector.ding.commons.util.spring;

import static com.vector.ding.context.WebContext.getApplicationContext;

import java.util.Map;

import org.springframework.context.ApplicationContext;

/**
 * provide bean obtain service, 
 * more action please use {@link WebContext#getApplicationContext()}
 * @author vector
 */
public final class SpringUtil {
	
	/**
	 * @param name
	 * @return
	 * @see ApplicationContext#getBean(String)
	 */
	@SuppressWarnings("unchecked")
	public static <T> T getBean(String name) {
		return (T) getApplicationContext().getBean(name);
	}
	
	/**
	 * @param name
	 * @return
	 * @see ApplicationContext#getBean(Class)
	 */
	public static <T> T getBean(Class<T> requiredType) {
		return (T) getApplicationContext().getBean(requiredType);
	}
	
	/**
	 * @param name
	 * @param requiredType
	 * @return
	 * @see ApplicationContext#getBean(String, Class)
	 */
	public static <T> T getBean(String name, Class<T> requiredType) {
		return getApplicationContext().getBean(name, requiredType);
	}
	
	/**
	 * @param name
	 * @return
	 * @see ApplicationContext#containsBean(String)
	 */
	public static boolean containsBean(String name) {
		return getApplicationContext().containsBean(name);
	}
	
	/**
	 * @param type
	 * @return
	 * @see ApplicationContext#getBeansOfType(Class)
	 */
	public static <T> Map<String, T> getBeansOfType(Class<T> type) {
		return getApplicationContext().getBeansOfType(type);
	}
	
}
